![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@codemirror/state
Advanced tools
The @codemirror/state package is part of the CodeMirror (version 6) ecosystem, which provides a flexible, extensible text editor. This particular package is responsible for managing the state of the editor, including the document content, selection, and any other state that plugins might add. It allows for the creation, modification, and querying of editor state, facilitating complex text editing features.
Creating an Editor State
This feature allows for the initialization of an editor state with a starting document. The document can be a string or a more complex structure for representing text.
{
import {EditorState} from '@codemirror/state';
const state = EditorState.create({doc: 'Hello, world!'});
}
Updating the State
This demonstrates how to update the state by creating a transaction. In this example, the text 'Hello' is replaced with 'Goodbye'. Transactions can include changes to the document, selections, and other state aspects.
{
import {EditorState, Transaction} from '@codemirror/state';
let newState = state.update({changes: {from: 0, to: 5, insert: 'Goodbye'}}).state;
}
Reading the State
This feature is about accessing the current content of the editor. It shows how to convert the document in the state to a string, which can be useful for saving the content or displaying it elsewhere.
{
import {EditorState} from '@codemirror/state';
const content = state.doc.toString();
}
The Monaco Editor is the code editor that powers VS Code, offering rich IntelliSense, validation, and advanced editing features. Compared to @codemirror/state, Monaco is a more comprehensive solution that includes its own state management but is heavier and less modular.
Ace is another embeddable code editor offering a wide range of features and language support. While it also manages editor state and provides similar functionality, it is designed as a monolithic package, making it less flexible than the modular approach of CodeMirror.
Draft.js is a framework for building rich text editors in React, focusing on immutable content and state management. It differs from @codemirror/state by being React-specific and focusing more on rich text editing rather than code editing, but it shares the concept of managing editor state in a comprehensive way.
[ WEBSITE | DOCS | ISSUES | FORUM | CHANGELOG ]
This package implements the editor state data structures for the CodeMirror code editor.
The project page has more information, a number of examples and the documentation.
This code is released under an MIT license.
We aim to be an inclusive, welcoming community. To make that explicit, we have a code of conduct that applies to communication around the project.
6.5.2 (2025-02-03)
Fix a bug where reconfiguring a field with a new init
value didn't update the value of the field.
FAQs
Editor state data structures for the CodeMirror code editor
The npm package @codemirror/state receives a total of 15,001 weekly downloads. As such, @codemirror/state popularity was classified as popular.
We found that @codemirror/state demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.